package git.jas0nch.final4it.service.impl;

import com.alibaba.fastjson.JSONObject;
import git.jas0nch.final4it.enums.AlgorithmEnum;
import git.jas0nch.final4it.enums.PyEnum;
import git.jas0nch.final4it.service.IMLService;
import git.jas0nch.final4it.util.PyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * projectName : final4it
 * className: MLServiceImpl
 * description: 执行py脚本的业务。
 *
 * @author : chengjiang@asiainfo.com
 * @since : 2022/05/05
 */

@Service
@Slf4j
public class MLServiceImpl implements IMLService {


    @Override
    public JSONObject executePY(String dataName) {
        try {
            String modelType = AlgorithmEnum.getModelString(dataName);
            // PyEnum.PY_DATA_ROAD ：服务器数据集的根路径的常量。
            String pyFullFileRoad = PyUtils.getPyFileRoad(PyEnum.PY_DATA_ROAD +dataName);
            // log 输出测试。
            log.info("modelType:{}, path: {}", modelType, pyFullFileRoad);
            return PyUtils.excutePy(pyFullFileRoad, modelType);
        } catch (IOException e) {
            e.printStackTrace();
            log.info("throw new exception: ",e);
            return null;
        }
    }
}
